package com.yq.cp.utils;

import org.apache.commons.codec.binary.Base64;
import org.junit.Test;

import javax.validation.ValidationProviderResolver;
import java.util.*;

/**
 * 采用MD5加密解密
 * @author tfq
 * @datetime 2011-10-13
 */
public class MD5Util {
    /***
     * MD5加码 生成32位md5码
     */
    public static String encode(String password){
        Base64 base64Encoder = new Base64();
        String encode = base64Encoder.encodeToString(password.getBytes());  // 加密
        System.out.println("加密为字符串:  " + encode);

        return encode;
    }

    /** 解密
     */
    public static String decoder(String encode){
        Base64 decoder = new Base64();
        String decode="";
        try {
            decode = new String ( decoder.decodeBase64(encode));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } // 解密
        System.out.println("解密为:  " + decode);
        return decode;
    }

    // 测试主函数
    public static void main(String args[]) {
        System.out.println(decoder("NjM2MzMz"));
        System.out.println(decoder("MTIz"));
        System.out.println(encode("123456"));

    }


}

